package property.personal.property_mange.utils;

import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

public class UploadUtils {
    //目标路径
    private static final String BASE_PATH="E:/image/";

    //
    private static final String SERVER_PATH="E:/image/";

    public static String upload(MultipartFile multipartFile){
        String filename=multipartFile.getOriginalFilename();
        String uuid= UUID.randomUUID().toString().replace("-","");

        String newfilename=uuid+"-"+filename;

        File file=new File(BASE_PATH,newfilename);

        try {
            multipartFile.transferTo(file);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return SERVER_PATH+newfilename;
    }
}
